<template>
  <div id="SupportDetailsList">
    <Header :currentCity="currentCity" :cityList="cityList"></Header>
    <Crumb :crumbListData="crumbListData"></Crumb>
    <div class="SupportDetailsList_wrap">
      <div class="SupportDetailsList_wrap_tabs">
        <div class="navAcitive">
          <ul>
            <li
              v-for="(item, index) in tabList"
              :key="index"
              :class="{ activeNameTipe: activeCode == index }"
            >
              <a :href="prefixUrl + item.href">{{ item.name }}</a>
            </li>
          </ul>
        </div>
        <div>
          <div id="tabNameAll">
            <div class="PropeIndex6_p1">
              <b>{{ HouseDetail.name }}</b>
              <span
                v-html="
                  HouseDetail.saleStatus == 1
                    ? '在售'
                    : HouseDetail.saleStatus == 2
                    ? '售罄'
                    : '待售'
                "
              >在售</span>
              <span
                style="color: #ef524d; font-weight: bold; font-size: 16px"
                v-if="HouseDetail.totalPrice && HouseDetail.totalPriceMax"
              >
                参考总价：{{ HouseDetail.totalPrice }}万-{{
                HouseDetail.totalPriceMax
                }}万
              </span>

              <span
                style="color: #ef524d; font-weight: bold; font-size: 16px"
                v-else-if="HouseDetail.totalPrice || HouseDetail.totalPriceMax"
              >参考总价：{{ HouseDetail.totalPrice }}万起</span>

              <span style="color: #ef524d; font-weight: bold; font-size: 16px" v-else>参考总价：价格待定</span>
              <div class="EstateDetail_li1_input EstateDetail_li1house">
                <input type="text" placeholder="请输入您的电话号码" maxlength="11" v-model="phone" />
                <button
                  @click="
                    clickType = 8;
                    subscribe(
                      '咨询返现详情',
                      '专业楼盘管家，深度解答！',
                      'https://mfgj.oss-cn-beijing.aliyuncs.com/upload/20211111/ec7c2095870d43459e3713b406281806.png'
                    );
                  "
                >免费咨询</button>
              </div>
            </div>
            <div class="EstatHouse">
              <div class="EstatHouse_nav">
                <el-radio-group v-model="HouseRoomListCode" @change="HouseRoomListChange">
                  <el-radio-button
                    v-for="(itms, inds) in HouseRoomList"
                    :key="inds"
                    :label="itms.roomNumName"
                  >{{ itms.roomNumName }}({{ itms.roomCount }})</el-radio-button>
                </el-radio-group>
              </div>
              <div class="EstatHouse_Li">
                <ul v-if="HouseRoomList">
                  <li
                    v-for="(item, index) in HouseRoomList[HouseRoomListIndex]
                      .roomList"
                    :key="index"
                  >
                    <div class="EstatHouse_Li_left float_left pic cursor">
                      <a :href="prefixUrl + item.urls" target="_blank">
                        <img
                          :src="item.imgUrl"
                          :title="HouseDetail.name + `楼盘户型图`"
                          :alt="HouseDetail.name + `楼盘户型图`"
                        />
                      </a>
                    </div>
                    <div class="EstatHouse_Li_center float_left cursor">
                      <a :href="prefixUrl + item.urls" target="_blank">
                        <div class="display EstatHouse_Li_center_p1">
                          <span
                            v-html="
                              item.saleStatus == 0
                                ? '待售'
                                : item.saleStatus == 1
                                ? '在售'
                                : '售罄'
                            "
                          ></span>
                          <span>{{ item.roomName }}</span>
                          <span
                            v-html="
                              item.area ? `建面` + item.area + `㎡` : '待定'
                            "
                          ></span>
                        </div>
                        <div class="display EstatHouse_Li_center_p2">
                          <span>
                            总价：
                            <b style="font-size: 20px" v-if="item.totalPrice">
                              {{ item.totalPrice }}万
                              <span style="font-size: 16px">起</span>
                            </b>
                            <b style="font-size: 24px" v-else>待定</b>
                          </span>
                          <p>
                            首付：
                            <span>
                              <b style="font-size: 20px" v-if="item.downPayments">
                                {{ item.downPayments }}万
                                <span style="font-size: 16px">起</span>
                              </b>
                              <b style="font-size: 16px" v-else>待定</b>
                            </span>
                          </p>
                        </div>
                        <div class="EstatHouse_Li_center_p3">
                          <p>
                            朝向：
                            <span
                              v-html="
                                item.orientation ? item.orientation : '待定'
                              "
                            ></span>
                          </p>
                        </div>
                        <div class="EstatHouse_Li_center_p4">
                          <span
                            v-for="(itemTag, indexTag) in item.tagCode"
                            :key="indexTag"
                          >{{ itemTag }}</span>
                        </div>
                      </a>
                    </div>
                    <div class="EstatHouse_Li_right float_right">
                      <p
                        class="cursor"
                        @click="
                          clickType = 8;
                          subscribe(
                            '咨询返现详情',
                            '专业楼盘管家，深度解答！',
                            'https://mfgj.oss-cn-beijing.aliyuncs.com/upload/20211111/ec7c2095870d43459e3713b406281806.png'
                          );
                        "
                      >了解户型返现金额</p>
                    </div>
                  </li>
                </ul>
              </div>
            </div>
            
            <!-- 关键区域，街道，周边 -->
            <keywordBox :currentCity="currentCity" :prefixUrl="prefixUrl" :regionList="regionList"></keywordBox>
          </div>
        </div>
      </div>
    </div>
    <Footer :currentCity="currentCity"></Footer>
    <!-- 弹窗按钮订阅 -->
    <PopupForm
      :show="popupform.show"
      :title="popupform.title"
      :desc="popupform.desc"
      :cover="popupform.cover"
      :phone="popupform.phone"
      :smsState="popupform.smsState"
      @phoneChange="phoneChange"
      @confirm="returnVisit"
      @cancel="
        popupform.show = false;
        popupform.background = '';
      "
    ></PopupForm>
    <!-- 订阅回调弹窗 -->
    <PopupSuccess
      :show="popupsubscribe.show"
      :cover="popupsubscribe.cover"
      :title="popupsubscribe.title"
      :desc="popupsubscribe.desc"
      @cancel="
        popupsubscribe.show = false;
        subscribeDisabled = false;
      "
    ></PopupSuccess>
  </div>
</template>

<script>
var head = {
  title: '成都✖✖✖✖✖✖✖✖✖✖', // 网页包头
  content: '成都✖✖✖✖✖✖✖✖✖✖', // 网页描述
  keywords: '成都,买房,管家,楼盘,买房网,✖✖✖✖✖✖✖✖✖✖', // 网页关键词
}
import axios from 'axios'
import u from '~/plugins/Ccom'
export default {
  head() {
    return {
      title: head.title,
      meta: [
        { name: 'description', content: head.content },
        { name: 'keywords', content: head.keywords },
      ],
      link: [
        {
          rel: 'stylesheet',
          href: `/css/lpgk.css?v=${new Date().getTime()}`,
        },
      ],
    }
  },
  data() {
    return {
      activeCode: 3,
      userInfo: '',
      HouseRoomListCode: '全部',
      HouseRoomListCode: '全部',
      HouseRoomListIndex: 0,
      phone: '',
      //组件订阅弹窗
      popupsubscribe: {
        show: false, //订阅数据
      },
      popupform: {
        show: false, //订阅成功数据
        phone: '',
      },
      clickType: '', // 1变价提醒2开盘提醒3咨询剩余房源4订阅楼盘动态5收藏楼盘6户型分析7电话咨询（询购房资格）8询返现9专车看房10咨询返现详情11咨询房贷首付
      subscribeDisabled: false,
    }
  },
  validate(ctx) {
    return /(.*?)\.html/.test(ctx.params.id)
  },
  async asyncData(ctx) {
    var prefixUrl = ctx.prefixUrl //域名
    var currentCity = ctx.currentCity //城市定位
    var cityList = ctx.cityList //
    var crumbListData = [] //栏目信息
    var estateId = ctx.params.id ? ctx.params.id.split('.')[0] : ''

    var tabList = [
      {
        name: '楼盘首页',
        href: `/lpxq/${estateId}.html`,
        aliases: '',
      },
      {
        name: '基础信息',
        href: `/lpxqxx/${estateId}.html`,
      },
      {
        name: '楼盘相册',
        href: `/lpxqxc/${estateId}.html`,
      },
      {
        name: '楼盘户型',
        href: `/lpxqhx/${estateId}.html`,
      },
      {
        name: '楼盘动态',
        href: `/lpxqdt/${estateId}.html`,
      },
      {
        name: '周边配套',
        href: `/lpxqpt/${estateId}.html`,
      },
      {
        name: '房价走势',
        href: `/lpxqzs/${estateId}.html`,
      },
      {
        name: '你问我答',
        href: `/lpxqwd/${estateId}.html`,
        aliases: 'wenda',
      },
      {
        name: '免费专车',
        href: `/mfzc/${estateId}.html`,
      },
    ]
    var HouseDetail = [] //楼盘详情数据

    var HouseRoomList = []
    var HouseRoomListTotal = ''
    var HouseRoomList_index = []

    // 获取楼盘详情
    var getMetro = await u.http({
      url: '/pc/houseDetail/queryHouseInfoDetailById',
      params: {
        estateId: estateId, //楼盘ID
        userId: '', //用户ID
      },
    })
    if (getMetro.code == 200) {
      HouseDetail = getMetro.data.houseInfoDetail
      head.title = `${HouseDetail.name},楼盘户型，周边配套，交通地图，${currentCity.cityName}✖✖✖✖✖✖✖✖✖✖`
      head.content = `✖✖✖✖✖✖✖✖✖✖为您提供${currentCity.cityName}${HouseDetail.name}户型图,${HouseDetail.name}原始户型图大全,要看详细,清晰的${HouseDetail.name}房型图就上✖✖✖✖✖✖✖✖✖✖`
      head.keywords = `${HouseDetail.name}楼盘户型图`

      // ==========楼盘面包屑============
      var regionCode = {
        title: `${HouseDetail.regionName}楼盘`,
        href: prefixUrl + `/lpcx/${HouseDetail.regionAliases}`,
      }
      // 202112071655 sry 合并路径
      var regionA = [HouseDetail.regionAliases]
      var streetA = [HouseDetail.streetAliases]
      var nowCrumbHref = u.emptyArrayIsNull(regionA.concat(streetA))
      if (HouseDetail.streetName && HouseDetail.streetAliases) {
        var streetCode = {
          title: `${HouseDetail.streetName}楼盘`,
          href: prefixUrl + `/lpcx/${nowCrumbHref.join('-')}`,
        }
      } else {
        var streetCode = null
      }

      var houseCode = {
        title: `${HouseDetail.name}`,
        href: prefixUrl + ctx.route.path,
      }

      // 修改栏目信息
      crumbListData = [
        {
          title: `${currentCity.cityName}✖✖✖✖✖✖✖✖✖✖`,
          href: prefixUrl,
        },
      ]

      if (streetCode) {
        crumbListData.push(regionCode, streetCode, houseCode)
      } else {
        crumbListData.push(regionCode, houseCode)
      }
      // ==========楼盘面包屑============
    } else {
      // 202111091818 sry
      return ctx.redirect('/error.html')
    }

    // 楼盘户型
    var RoomList = await u.http({
      url: '/pc/houseRoom/queryHouseRoomList',
      params: {
        estateId: estateId, //楼盘ID
      },
    })
    if (RoomList.code == 200) {
      HouseRoomList = RoomList.data
      HouseRoomList.forEach((item) => {
        item.roomList.forEach((ites) => {
          ites.urls = `/lpxqhxxq/${estateId}.html?roomId=${ites.roomId}`
          if (ites.tagNames == '' || ites.tagNames == null) {
            ites.tagCode = []
          } else {
            ites.tagCode = ites.tagNames.split(',')
          }
        })
      })
    }

    // 首页楼盘户型
    var queryHouse = await u.http({
      url: '/app/houseRoom/queryHouseRoomList',
      params: {
        estateId: estateId, //楼盘ID
        pageNum: 1, //显示第几页
        pageSize: 4, //一页显示多少条
        roomNum: '', //几室
      },
    })
    if (queryHouse.code == 200) {
      queryHouse.data.list.forEach((item) => {
        item.href = `/lpxqhxxq/${estateId}.html?roomId=${item.roomId}`
      })
      HouseRoomList_index = queryHouse.data.list
      queryHouse.data.list.forEach((item) => {
        if (item.tagNames == null || item.tagNames == '') {
          item.tagCode = []
        } else {
          item.tagCode = item.tagNames.split(',')
        }
      })
    }

    return {
      tabList,
      prefixUrl,
      currentCity,
      cityList,
      crumbListData,
      estateId,
      HouseDetail,
      HouseRoomList,
      HouseRoomListTotal,
      HouseRoomList_index,
      regionList: ctx.regionList
    }
  },

  mounted() {},
  methods: {
    // =========户型数据显示隐藏============
    HouseRoomListChange(e) {
      this.HouseRoomList.forEach((itemDs, indexDs) => {
        if (itemDs.roomNumName == e) {
          this.HouseRoomListIndex = indexDs
        }
      })
    },
    // ==========================订阅回访消息==================================
    // 预约
    subscribe(title, desc, cover, titleend) {
      this.popupform.show = true
      this.popupform.title = title
      this.popupform.cover = cover
      this.popupform.smsState = this.smsState
      this.popupform.desc = desc
      if (localStorage.getItem('mobile')) {
        this.popupform.phone = Number(localStorage.getItem('mobile'))
      }
      this.popupsubscribe.title = titleend
    },
    // 登录成功回调
    returnVisit() {
      this.popupform.show = false
      this.subscribeDisabled = true
      let url = getCookie('token')
        ? '/app/visitRecord/addVisitRecord'
        : '/app/visitRecord/addVisitRecordByNoToken'
      u.http({
        client: true,
        url,
        headers: {
          token: getCookie('token') || '',
        },
        params: {
          clickType: this.clickType,
          phone: this.popupform.phone,
          estateId: this.estateId,
        },
      }).then((res) => {
        this.popupsubscribe.show = true
      })
    },
    // 监听手机号
    phoneChange(e) {
      this.popupform.phone = e
    },
  },
}
</script>